home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 21
/
Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso
/
Aminet
/
gfx
/
misc
/
PicSort.lha
/
PicSort
/
PicSort.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1997-08-14
|
23KB
|
789 lines
/*************************************************************************/
/* $VER: PicSort.rexx 1.21 (12.08.97) */
/* Script to sort pictures into several directories */
/* Usage: rx PicSort */
/*************************************************************************/
dummy = '"'||Pragma("D")
if right(dummy,1)~=":" THEN dummy = dummy || '/'
IF ~(Exists("Libs:reqtools.library")&Exists("Libs:rexxreqtools.library")) THEN
ADDRESS COMMAND "ASSIGN LIBS: "||dummy||'Libs" ADD'
IF ~Exists("C:VAREXX") THEN ADDRESS COMMAND "ASSIGN C: "||dummy||'bin" ADD'
gui_file = dummy || 'GUI/PicSort.GUI"'
viewer = 'sys:Utilities/FastView %s '
thump = 0
thumpcom = ""
path1 = ""
path2 = ""
path3 = ""
path4 = ""
path5 = ""
path6 = ""
path7 = ""
path8 = ""
path9 = ""
path10 = ""
path11 = ""
path12 = ""
path13 = ""
path14 = ""
path15 = ""
path16 = ""
path17 = ""
path18 = ""
path19 = ""
path20 = ""
button1 = ""
button2 = ""
button3 = ""
button4 = ""
button5 = ""
button6 = ""
button7 = ""
button8 = ""
button9 = ""
button10 = ""
button11 = ""
button12 = ""
button13 = ""
button14 = ""
button15 = ""
button16 = ""
button17 = ""
button18 = ""
button19 = ""
button20 = ""
result = ""
IF EXISTS("libs:rexxsupport.library") THEN DO
IF ~SHOW("L","rexxsupport.library") THEN
IF ~ADDLIB("rexxsupport.library",0,-30,0) THEN EXIT
END
ELSE EXIT
IF EXISTS("libs:rexxreqtools.library") THEN DO
IF ~SHOW("L","rexxreqtools.library") THEN
IF ~ADDLIB("rexxreqtools.library",0,-30) THEN EXIT
END
ELSE EXIT
OPTIONS RESULTS
OPTIONS FAILAT 11
SIGNAL ON SYNTAX
SIGNAL ON FAILURE
/* Check Varexx is loaded if not load it */
IF SHOW( 'p', 'VAREXX' ) ~= 1 THEN DO
ADDRESS COMMAND "run >NIL: varexx"
ADDRESS COMMAND "WaitForPort VAREXX"
END
ADDRESS VAREXX
portname = "PICPORT"
portcount = 0
do until show("P",portname||portcount)=0
portcount = portcount + 1
end
portname = portname || portcount
say portname
IF OPENPORT(portname) = 0 THEN DO
CALL rtezrequest "Could not open a port.",, "Varexx Error"
EXIT
END
'load ' gui_file portname
vhost = RESULT
ADDRESS VALUE vhost
show
/**************************************************************************/
/* Load Config if any exists */
/**************************************************************************/
config_file = "picsort.cfg"
if exists(config_file) THEN DO
OPEN(config,config_file,"READ")
test = ReadLn(config)
IF test = "PicSort_CONFIG12" THEN DO
button1 = ReadLn(config)
path1 = ReadLn(config)
button2 = ReadLn(config)
path2 = ReadLn(config)
button3 = ReadLn(config)
path3 = ReadLn(config)
button4 = ReadLn(config)
path4 = ReadLn(config)
button5 = ReadLn(config)
path5 = ReadLn(config)
button6 = ReadLn(config)
path6 = ReadLn(config)
button7 = ReadLn(config)
path7 = ReadLn(config)
button8 = ReadLn(config)
path8 = ReadLn(config)
button9 = ReadLn(config)
path9 = ReadLn(config)
button10 = ReadLn(config)
path10 = ReadLn(config)
button11 = ReadLn(config)
path11 = ReadLn(config)
button12 = ReadLn(config)
path12 = ReadLn(config)
button13 = ReadLn(config)
path13 = ReadLn(config)
button14 = ReadLn(config)
path14 = ReadLn(config)
button15 = ReadLn(config)
path15 = ReadLn(config)
button16 = ReadLn(config)
path16 = ReadLn(config)
button17 = ReadLn(config)
path17 = ReadLn(config)
button18 = ReadLn(config)
path18 = ReadLn(config)
button19 = ReadLn(config)
path19 = ReadLn(config)
button20 = ReadLn(config)
path20 = ReadLn(config)
viewer = ReadLn(config)
thump = ReadLn(config)
thumpcom = ReadLn(config)
thumpsuf = ReadLn(config)
END
else dummy=rtezrequest("That's no config file","Okay","Error:","",dummy)
CLOSE(config)
END
else DO
dummy=rtezrequest("No config loaded","Okay","Error:","",dummy)
END
/**************************************************************************/
/* MAIN LOOP -- Check for GUI events */
/**************************************************************************/
if ~exists("ENVARC:PicSort.mrk") THEN DO
dummy=rtezrequest("If anything does not work:"||'0A'x||"Please check the prefs"||'0A'x||"AND READ THE DOCS","So I do","WARNING:","",dummy)
dummy = Open(file,"ENVARC:PicSort.mrk","W")
dummy = WriteLn(file,"DONE")
dummy = Close(file)
end
DO FOREVER
CALL WAITPKT(portname)
packet = GETPKT(portname)
IF packet ~= '00000000'x THEN DO
class = GETARG(packet)
event = SUBWORD(class,1,1)
parameter = SUBWORD(class,2)
if event = "CLOSEWINDOW" THEN LEAVE
if event = "QUIT" THEN LEAVE
if event = "CONFIG" THEN config()
if event = "SORT" THEN sort()
END
END
'hide unload'
CALL CLOSEPORT( portname )
EXIT
/*
** Subroutines
*/
config:
BUSY SET
SPAWN portname
oldadr = RESULT
ADDRESS value oldadr
'show' "PicSort_CONFIG"
show_config()
DO FOREVER
CALL WAITPKT(portname)
packet = GETPKT(portname)
IF packet ~= '00000000'x THEN DO
class = GETARG(packet)
event = SUBWORD(class,1,1)
parameter = SUBWORD(class,2)
if event = "CLOSEWINDOW" THEN LEAVE
if event = "BUTTON1" THEN DO
button1 = parameter
path1 = getdir(path1)
END
if event = "BUTTON2" THEN DO
button2 = parameter
path2 = getdir(path2)
END
if event = "BUTTON3" THEN DO
button3 = parameter
path3 = getdir(path3)
END
if event = "BUTTON4" THEN DO
button4 = parameter
path4 = getdir(path4)
END
if event = "BUTTON5" THEN DO
button5 = parameter
path5 = getdir(path5)
END
if event = "BUTTON6" THEN DO
button6 = parameter
path6 = getdir(path6)
END
if event = "BUTTON7" THEN DO
button7 = parameter
path7 = getdir(path7)
END
if event = "BUTTON8" THEN DO
button8 = parameter
path8 = getdir(path8)
END
if event = "BUTTON9" THEN DO
button9 = parameter
path9 = getdir(path9)
END
if event = "BUTTON10" THEN DO
button10 = parameter
path10 = getdir(path10)
END
if event = "GET1" THEN path1 = getdir(path1)
if event = "GET2" THEN path2 = getdir(path2)
if event = "GET3" THEN path3 = getdir(path3)
if event = "GET4" THEN path4 = getdir(path4)
if event = "GET5" THEN path5 = getdir(path5)
if event = "GET6" THEN path6 = getdir(path6)
if event = "GET7" THEN path7 = getdir(path7)
if event = "GET8" THEN path8 = getdir(path8)
if event = "GET9" THEN path9 = getdir(path9)
if event = "GET10" THEN path10 = getdir(path10)
if event = "VIEWER" THEN viewer = parameter
if event = "OKAY" THEN LEAVE
if event = "SAVE" THEN save_config()
if event = "LOAD" THEN load_config()
if event = "BUTTONS2" THEN buttons2()
say event
show_config()
END
END
'hide'
ADDRESS VALUE vhost
BUSY
RETURN 0
buttons2:
BUSY SET
SPAWN portname
ADDRESS value RESULT
'show' "PicSort_CONFIG2"
show_config2()
DO FOREVER
CALL WAITPKT(portname)
packet = GETPKT(portname)
IF packet ~= '00000000'x THEN DO
class = GETARG(packet)
event = SUBWORD(class,1,1)
parameter = SUBWORD(class,2)
if event = "CLOSEWINDOW" THEN LEAVE
if event = "BUTTON11" THEN DO
button11 = parameter
path11 = getdir(path11)
END
if event = "BUTTON12" THEN DO
button12 = parameter
path12 = getdir(path12)
END
if event = "BUTTON13" THEN DO
button13 = parameter
path13 = getdir(path13)
END
if event = "BUTTON14" THEN DO
button14 = parameter
path14 = getdir(path14)
END
if event = "BUTTON15" THEN DO
button15 = parameter
path15 = getdir(path15)
END
if event = "BUTTON16" THEN DO
button16 = parameter
path16 = getdir(path16)
END
if event = "BUTTON17" THEN DO
button17 = parameter
path17 = getdir(path17)
END
if event = "BUTTON18" THEN DO
button18 = parameter
path18 = getdir(path18)
END
if event = "BUTTON19" THEN DO
button19 = parameter
path19 = getdir(path19)
END
if event = "BUTTON20" THEN DO
button20 = parameter
path20 = getdir(path20)
END
say event parameter
if event = "THUMBNAILS" then thump=parameter
if event = "COMMAND" then thumpcom = parameter
if event = "SUFFIX" then thumpsuf = parameter
if event = "GET11" THEN path11 = getdir(path11)
if event = "GET12" THEN path12 = getdir(path12)
if event = "GET13" THEN path13 = getdir(path13)
if event = "GET14" THEN path14 = getdir(path14)
if event = "GET15" THEN path15 = getdir(path15)
if event = "GET16" THEN path16 = getdir(path16)
if event = "GET17" THEN path17 = getdir(path17)
if event = "GET18" THEN path18 = getdir(path18)
if event = "GET19" THEN path19 = getdir(path19)
if event = "GET20" THEN path20 = getdir(path20)
if event = "OKAY" THEN LEAVE
show_config2()
END
END
'hide'
ADDRESS VALUE oldadr
BUSY
RETURN 0
load_config:
call rtfreefilebuffer()
drop config_file result
tag = "rtfi_flags = freqf_patgad rtfi_matchpat = #?.cfg"
config_file = rtfilerequest("","picsort.cfg","Load Configuration","Load",tag,result)
if config_file ~= "" THEN DO
OPEN(config,config_file,"READ")
test = ReadLn(config)
IF test = "PicSort_CONFIG12" THEN DO
button1 = ReadLn(config)
path1 = ReadLn(config)
button2 = ReadLn(config)
path2 = ReadLn(config)
button3 = ReadLn(config)
path3 = ReadLn(config)
button4 = ReadLn(config)
path4 = ReadLn(config)
button5 = ReadLn(config)
path5 = ReadLn(config)
button6 = ReadLn(config)
path6 = ReadLn(config)
button7 = ReadLn(config)
path7 = ReadLn(config)
button8 = ReadLn(config)
path8 = ReadLn(config)
button9 = ReadLn(config)
path9 = ReadLn(config)
button10 = ReadLn(config)
path10 = ReadLn(config)
button11 = ReadLn(config)
path11 = ReadLn(config)
button12 = ReadLn(config)
path12 = ReadLn(config)
button13 = ReadLn(config)
path13 = ReadLn(config)
button14 = ReadLn(config)
path14 = ReadLn(config)
button15 = ReadLn(config)
path15 = ReadLn(config)
button16 = ReadLn(config)
path16 = ReadLn(config)
button17 = ReadLn(config)
path17 = ReadLn(config)
button18 = ReadLn(config)
path18 = ReadLn(config)
button19 = ReadLn(config)
path19 = ReadLn(config)
button20 = ReadLn(config)
path20 = ReadLn(config)
viewer = ReadLn(config)
thump = ReadLn(config)
thumpcom = ReadLn(config)
thumpsuf = ReadLn(config)
END
else dummy=rtezrequest("That's no config file","Okay","Error:","",dummy)
CLOSE(config)
END
RETURN 0
save_config:
call rtfreefilebuffer()
drop config_file result
tag = "rtfi_flags = freqf_patgad rtfi_matchpat = #?.cfg"
config_file = rtfilerequest("","picsort.cfg","Save Configuration","Save",tag,result)
if config_file ~= "" THEN DO
OPEN(config,config_file,"WRITE")
WriteLn(config,"PicSort_CONFIG12")
WriteLn(config,button1)
WriteLn(config,path1)
WriteLn(config,button2)
WriteLn(config,path2)
WriteLn(config,button3)
WriteLn(config,path3)
WriteLn(config,button4)
WriteLn(config,path4)
WriteLn(config,button5)
WriteLn(config,path5)
WriteLn(config,button6)
WriteLn(config,path6)
WriteLn(config,button7)
WriteLn(config,path7)
WriteLn(config,button8)
WriteLn(config,path8)
WriteLn(config,button9)
WriteLn(config,path9)
WriteLn(config,button10)
WriteLn(config,path10)
WriteLn(config,button11)
WriteLn(config,path11)
WriteLn(config,button12)
WriteLn(config,path12)
WriteLn(config,button13)
WriteLn(config,path13)
WriteLn(config,button14)
WriteLn(config,path14)
WriteLn(config,button15)
WriteLn(config,path15)
WriteLn(config,button16)
WriteLn(config,path16)
WriteLn(config,button17)
WriteLn(config,path17)
WriteLn(config,button18)
WriteLn(config,path18)
WriteLn(config,button19)
WriteLn(config,path19)
WriteLn(config,button20)
WriteLn(config,path20)
WriteLn(config,viewer)
WriteLn(config,thump)
WriteLn(config,thumpcom)
WriteLn(config,thumpsuf)
Close(config)
END
RETURN 0
show_config:
Settext "BUTTON1" button1
Settext "DEST1" path1
Settext "BUTTON2" button2
Settext "DEST2" path2
Settext "BUTTON3" button3
Settext "DEST3" path3
Settext "BUTTON4" button4
Settext "DEST4" path4
Settext "BUTTON5" button5
Settext "DEST5" path5
Settext "BUTTON6" button6
Settext "DEST6" path6
Settext "BUTTON7" button7
Settext "DEST7" path7
Settext "BUTTON8" button8
Settext "DEST8" path8
Settext "BUTTON9" button9
Settext "DEST9" path9
Settext "BUTTON10" button10
Settext "DEST10" path10
Settext "VIEWER" viewer
RETURN 0
show_config2:
Settext "BUTTON11" button11
Settext "DEST11" path11
Settext "BUTTON12" button12
Settext "DEST12" path12
Settext "BUTTON13" button13
Settext "DEST13" path13
Settext "BUTTON14" button14
Settext "DEST14" path14
Settext "BUTTON15" button15
Settext "DEST15" path15
Settext "BUTTON16" button16
Settext "DEST16" path16
Settext "BUTTON17" button17
Settext "DEST17" path17
Settext "BUTTON18" button18
Settext "DEST18" path18
Settext "BUTTON19" button19
Settext "DEST19" path19
Settext "BUTTON20" button20
Settext "DEST20" path20
Settext "COMMAND" thumpcom
Settext "SUFFIX" thumpsuf
if thump = TRUE then do
setcheck "THUMBNAILS" check
set "COMMAND" enable
set "SUFFIX" enable
end
if thump = FALSE then do
setcheck "THUMBNAILS"
set "COMMAND" disable
set "SUFFIX" disable
end
RETURN 0
sort:
BUSY SET
SPAWN portname
ADDRESS value RESULT
Setlabel "SORT1" button1
Setlabel "SORT2" button2
Setlabel "SORT3" button3
Setlabel "SORT4" button4
Setlabel "SORT5" button5
Setlabel "SORT6" button6
Setlabel "SORT7" button7
Setlabel "SORT8" button8
Setlabel "SORT9" button9
Setlabel "SORT10" button10
Setlabel "SORT11" button11
Setlabel "SORT12" button12
Setlabel "SORT13" button13
Setlabel "SORT14" button14
Setlabel "SORT15" button15
Setlabel "SORT16" button16
Setlabel "SORT17" button17
Setlabel "SORT18" button18
Setlabel "SORT19" button19
Setlabel "SORT20" button20
'show' "PicSort_SORT"
if path1="" THEN SET "SORT1" DISABLE
if path2="" THEN SET "SORT2" DISABLE
IF path3="" THEN SET "SORT3" DISABLE
if path4="" THEN SET "SORT4" DISABLE
if path5="" THEN SET "SORT5" DISABLE
IF path6="" THEN SET "SORT6" DISABLE
IF path7="" THEN SET "SORT7" DISABLE
if path8="" THEN SET "SORT8" DISABLE
if path9="" THEN SET "SORT9" DISABLE
IF path10="" THEN SET "SORT10" DISABLE
if path11="" THEN SET "SORT11" DISABLE
if path12="" THEN SET "SORT12" DISABLE
IF path13="" THEN SET "SORT13" DISABLE
IF path14="" THEN SET "SORT14" DISABLE
if path15="" THEN SET "SORT15" DISABLE
if path16="" THEN SET "SORT16" DISABLE
IF path17="" THEN SET "SORT17" DISABLE
if path18="" THEN SET "SORT18" DISABLE
if path19="" THEN SET "SORT19" DISABLE
IF path20="" THEN SET "SORT20" DISABLE
call rtfreefilebuffer()
drop result bild
tag = "rtfi_flags = freqf_multiselect|freqf_patgad rtfi_matchpat = #?"
result = rtfilerequest("Sys:","","Select Pictures to sort","Sort",tag,bild)
if result ~= "" THEN DO
DO i = 1 to bild.count
bild.i = '"'||bild.i||'"'
viewstring = INSERT( bild.i , viewer , POS("%s", viewer )+1 )
viewstring = DELSTR( viewstring , POS("%s",viewstring) , 2 )
Settext "FILE" bild.i
address command viewstring
if rc ~=0 THEN dummy=rtezrequest("Could not show picture!"||'0A'x||"Please check the prefs.","So I do","WARNING:","",dummy)
DO FOREVER
busy
CALL WAITPKT(portname)
busy set
packet = GETPKT(portname)
IF packet ~= '00000000'x THEN DO
class = GETARG(packet)
event = SUBWORD(class,1,1)
parameter = SUBWORD(class,2)
if event = "CLOSEWINDOW" THEN LEAVE
if event = "RESHOW" THEN do
address command viewstring
if rc ~=0 THEN dummy=rtezrequest("Could not show picture!"||'0A'x||"Please check the prefs.","So I do","WARNING:","",dummy)
end
if class = "KEYBOARD ESC" THEN event = "CLOSEWINDOW"
if pos("SORT",event)~=0 THEN LEAVE
if event = "DELETE" THEN LEAVE
if event = "PLUS" THEN LEAVE
if (event = "KEYBOARD") & (parameter = "DELETE") THEN LEAVE
END
END
if event = "CLOSEWINDOW" THEN LEAVE
if (event = "DELETE")|((event = "KEYBOARD")&(parameter = "DELETE")) THEN DO
ret = rtezrequest("Delete file ?","_Delete|_Cancel","WARNING:",,result)
if ret = 1 THEN ADDRESS COMMAND "delete "||bild.i
END
string = ""
if event = ("SORT1") THEN string = path1
if event = ("SORT2") THEN string = path2
if event = ("SORT3") THEN string = path3
if event = ("SORT4") THEN string = path4
if event = ("SORT5") THEN string = path5
if event = ("SORT6") THEN string = path6
if event = ("SORT7") THEN string = path7
if event = ("SORT8") THEN string = path8
if event = ("SORT9") THEN string = path9
if event = ("SORT10") THEN string = path10
if event = ("SORT11") THEN string = path11
if event = ("SORT12") THEN string = path12
if event = ("SORT13") THEN string = path13
if event = ("SORT14") THEN string = path14
if event = ("SORT15") THEN string = path15
if event = ("SORT16") THEN string = path16
if event = ("SORT17") THEN string = path17
if event = ("SORT18") THEN string = path18
if event = ("SORT19") THEN string = path19
if event = ("SORT20") THEN string = path20
if string ~= "" THEN DO
copied = 0
cpath = string
string = bild.i || ' "' || string || '"'
pdest = left(subword(string,2),length(subword(string,2))-1)||getfilename(bild.i)||'"'
tdest = left(subword(string,2),length(subword(string,2))-1)||getfilename(bild.i)||thumpsuf||'"'
overwrite = TRUE
if (exists(compress(pdest,'"'))|exists(compress(tdest,'"'))) then do
dummy=rtezrequest("A picture or thumbnail"||'0A'x||"with this name already exists!","Replace|Skip","WARNING:","",dummy)
if dummy = 0 then overwrite = FALSE
end
if (thump = TRUE)&(overwrite = TRUE) then do
tsource = bild.i
tdest = left(subword(string,2),length(subword(string,2))-1)||getfilename(bild.i)||thumpsuf||'"'
tcom = INSERT( tsource , thumpcom , POS("%s", thumpcom )+1 )
tcom = DELSTR( tcom , POS("%s",tcom) , 2 )
tcom = INSERT( tdest , tcom , POS("%d", tcom )+1 )
tcom = DELSTR( tcom , POS("%d",tcom) , 2 )
address command tcom
if rc ~=0 THEN dummy=rtezrequest("Could not generate thumbnail!"||'0A'x||"Please check the prefs.","So I do","WARNING:","",dummy)
end
if overwrite = TRUE THEN DO
ADDRESS COMMAND "copy "||string||" CLONE"
copied = RC
if copied ~= 0 THEN dummy=rtezrequest("Could not move picture!"||'0A'x||"Please check the prefs.","So I do","WARNING:","",dummy)
IF copied = 0 THEN ADDRESS COMMAND "delete "||bild.i
end
END
END
END
'hide'
ADDRESS VALUE vhost
BUSY
RETURN 0
/*
** Subprocedures
*/
getdir:
Parse Arg olddir
drop dir result
call rtfreefilebuffer()
tag = "rtfi_flags = freqf_nofiles"
dir = rtfilerequest(olddir,,"Select Directory","Okay",tag,result)
RETURN dir
GetFileName:
PARSE ARG OldFilename
FirstChar = LEFT( OldFilename, 1 )
if (FirstChar = '"') | (FirstChar = '''') THEN
OldFilename = STRIP( OldFilename, "B", FirstChar )
FNameSepPos = LASTPOS( '/', OldFilename )
if (FNameSepPos = 0) THEN
FNameSepPos = LASTPOS( ':', OldFilename )
if (FNameSepPos ~= 0) THEN
FileOnly = RIGHT( OldFilename, LENGTH( OldFilename ) - FNameSepPos )
else
FileOnly = OldFilename
RETURN FileOnly
GetPath:
PARSE ARG OldFilename
FirstChar = LEFT( OldFilename, 1 )
if (FirstChar = '"') | (FirstChar = '''') THEN
OldFilename = STRIP( OldFilename, "B", FirstChar )
FNameSepPos = LASTPOS( '/', OldFilename )
if (FNameSepPos = 0) THEN
FNameSepPos = LASTPOS( ':', OldFilename )
if (FNameSepPos ~= 0) THEN
PathOnly = LEFT( OldFilename, FNameSepPos )
else
PathOnly = ""
RETURN PathOnly
/* Error messages */
failure:
SAY "Error code" rc "-- Line" SIGL
SAY EXTERNERROR
'hide unload'
CALL CLOSEPORT (portname)
EXIT
syntax:
SAY "Error" rc "-- Line" SIGL
SAY ERRORTEXT( rc )
'hide unload'
CALL CLOSEPORT (portname)
EXIT